//
//  HealthModel.m
//  Liuhe
//
//  Created by zr on 2018/8/20.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "HealthModel.h"

@implementation HealthModel


+(instancetype)modelWithDictionary:(NSDictionary *)dic{
    
    HealthModel *model =[[HealthModel alloc] init];
    
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
}


+(void)healthModelWithType:(NSString *)type WithSucess:(void (^)(NSArray<HealthModel *> *))sucessBlock error:(void (^)(void))errorBlock{
    
    //    NSDictionary * parameters;
    NSString * url = [NSString stringWithFormat:@"/appstore/health/search?key=276cd36bb45f0&name=%@",type];
    
    NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
    NSString *encodeUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
    
    [[MobNetworkingTool sharedTools] GET:encodeUrl parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        //        NSLog(@"====%@",responseObject);
        NSDictionary * dict = responseObject[@"result"];
        
        NSArray * paramArray = dict[@"list"];
        
        //            NSLog(@"==%@",paramArray);
        
        NSMutableArray *mArray = [NSMutableArray array];
        
        [paramArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            HealthModel * model = [HealthModel modelWithDictionary:obj];
            
            [mArray addObject:model];
            
        }];
        
        if(sucessBlock){
            sucessBlock(mArray.copy);
        }
        
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
        NSLog(@"errror===%@",error);
    }];
    
}


-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
}


@end
